/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.stock.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.common.collect.Lists;
import com.thinkgem.jeesite.modules.stock.entity.SpdDetail;
import com.thinkgem.jeesite.modules.stock.entity.StockWarehouse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.stock.entity.ContainerDetail;
import com.thinkgem.jeesite.modules.stock.service.ContainerDetailService;

import java.util.List;

/**
 * 托盘明细Controller
 * @author 托盘明细
 * @version 2019-12-21
 */
@Controller
@RequestMapping(value = "${adminPath}/stock/containerDetail")
public class ContainerDetailController extends BaseController {

	@Autowired
	private ContainerDetailService containerDetailService;
	
	@ModelAttribute
	public ContainerDetail get(@RequestParam(required=false) String id) {
		ContainerDetail entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = containerDetailService.get(id);
		}
		if (entity == null){
			entity = new ContainerDetail();
		}
		return entity;
	}
	
	@RequiresPermissions("stock:containerDetail:view")
	@RequestMapping(value = {"list", ""})
	public String list(ContainerDetail containerDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ContainerDetail> page = containerDetailService.findPage(new Page<ContainerDetail>(request, response), containerDetail); 
		model.addAttribute("page", page);
		return "modules/stock/containerDetailList";
	}

	@RequiresPermissions("stock:containerDetail:view")
	@RequestMapping(value = "form")
	public String form(ContainerDetail containerDetail, Model model) {
		model.addAttribute("containerDetail", containerDetail);
		return "modules/stock/containerDetailForm";
	}

	@RequiresPermissions("stock:containerDetail:edit")
	@RequestMapping(value = "save")
	public String save(ContainerDetail containerDetail, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, containerDetail)){
			return form(containerDetail, model);
		}
		containerDetailService.save(containerDetail);
		addMessage(redirectAttributes, "保存托盘明细成功");
		return "redirect:"+Global.getAdminPath()+"/stock/containerDetail/?repage";
	}
	@RequiresPermissions("stock:containerDetail:view")
	@RequestMapping(value = {"alllist"})
	@ResponseBody
	public List<ContainerDetail> alllist(ContainerDetail stockWarehouse, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<ContainerDetail> ls=containerDetailService.findList(stockWarehouse);

		return ls;

	}
	@RequiresPermissions("stock:containerDetail:edit")
	@RequestMapping(value = "delete")
	public String delete(ContainerDetail containerDetail, RedirectAttributes redirectAttributes) {
		containerDetailService.delete(containerDetail);
		addMessage(redirectAttributes, "删除托盘明细成功");
		return "redirect:"+Global.getAdminPath()+"/stock/containerDetail/?repage";
	}

}